GenomicPlot: an R package for efficient and flexible visualization of NGS coverage profiles

Shuye Pu

2023-05-05

Introduction

Visualization of next generation sequencing (NGS) data at various genomic features on a genome-wide scale provides an effective way of exploring and communicating experimental results on one hand, yet poses as a tremendous challenge on the other hand, due to the huge amount of data to be processed. Existing software tools like deeptools, ngs.plot, coverageView and metagene2, while having attractive features and perform reasonably well in relatively simple scenarios, like plotting coverage profiles of fixed genomic loci or regions, have serious limitations in terms of efficiency and flexibility. For instance, deeptools requires 3 steps (3 sub-programs to be run) to generate plots from input files: first, convert .bam files to .bigwig format; second, compute coverage matrix; and last, plot genomic profiles. Huge amount of intermediate data are generated along the way and additional efforts have to be made to integrate these 3 closely related steps. All of them focus on plotting signals within genomic regions or around genomic loci, but not within or around combinations of genomic features. None of them have the capability of performing statistical tests on the data displayed in the profile plots.

To meet the diverse needs of experimental biologists, we have developed GenomicPlot using rich resources available on the R platform (particularly, the Bioconductor). Our GenomicPlot has the following major features:

Plot gene/metagene with 5’UTR, CDS and 3’UTR

The lengths of each part of the genes are prorated based on the median length of 5’UTR, CDS and 3’UTR of protein-coding genes in the genome. The total length (including upstream and downstream extensions) are divided into the specified number of bins. Subsets of genes can be plotted as overlays for comparison.

library(GenomicPlot, quietly=TRUE)
txdb <- AnnotationDbi::loadDb(system.file("extdata", "txdb_chr19.sql", package="GenomicPlot"))
gf <- prepare_5parts_genomic_features(txdb, meta=TRUE, nbins=100, fiveP=-2000, threeP=1000, 
                                      longest=TRUE)

queryfiles <- system.file("extdata", "treat_chr19.bam", package="GenomicPlot")
names(queryfiles) <- "clip_bam"
inputfiles <- system.file("extdata", "input_chr19.bam", package="GenomicPlot")
names(inputfiles) <- "clip_input"

importParams <- list(offset=-1, fix_width=0, fix_point="start", norm=TRUE, 
                          useScore=FALSE, outRle=TRUE, useSizeFactor=FALSE, genome="hg19")

plot_5parts_metagene(queryFiles=queryfiles, 
                     gFeatures_list=list("metagene"=gf), 
                     inputFiles=inputfiles, 
                     scale=FALSE, 
                     verbose=FALSE, 
                     transform=NA, 
                     smooth=TRUE, 
                     stranded=TRUE, 
                     outPrefix=NULL, 
                     importParams=importParams, 
                     heatmap=TRUE, 
                     rmOutlier=0, 
                     nc=5)
Individual sample profile and heatmap

Individual sample profile and heatmap

Profile overlay

Profile overlay

Ratio-over-input profile and heatmap

Ratio-over-input profile and heatmap

Plot gene/metagene body

The lengths of each part of the profile plot are prorated to the lengths of upstream and downstream extensions as well as the median length of protein-coding genes in the genome. The total length (including upstream and downstream extensions) are divided into the specified number of bins.

txdb <- AnnotationDbi::loadDb(system.file("extdata", "txdb_chr19.sql", package="GenomicPlot"))
gf <- prepare_3parts_genomic_features(txdb, meta=FALSE, nbins=100, fiveP=-3000, threeP=2000, 
                                      longest=TRUE)

queryfiles <- system.file("extdata", "chip_treat_chr19.bam", package="GenomicPlot")
names(queryfiles) <- "chip_bam"
inputfiles <- system.file("extdata", "chip_input_chr19.bam", package="GenomicPlot")
names(inputfiles) <- "chip_input"

importParams <- list(offset=0, fix_width=150, fix_point="start", norm=TRUE, 
                          useScore=FALSE, outRle=TRUE, useSizeFactor=TRUE, genome="hg19")

plot_3parts_metagene(queryFiles=queryfiles, 
                     gFeatures=gf, 
                     inputFiles=inputfiles, 
                     scale=FALSE, 
                     verbose=FALSE, 
                     transform=NA, 
                     smooth=TRUE, 
                     stranded=TRUE, 
                     outPrefix=NULL, 
                     importParams=importParams, 
                     heatmap=TRUE, 
                     rmOutlier=0, 
                     nc=5)
Individual sample profile and heatmap

Individual sample profile and heatmap

Profile overlay

Profile overlay

Ratio-over-input profile and heatmap

Ratio-over-input profile and heatmap

Plot along the ranges of genomic features

Signal profile along with heatmaps in genomic features or user defined genomic regions provided through a .bed file or narrowPeak file can be plotted. Multiple samples (.bam files) and multiple set of regions (.bed file) can be overlayed on the same figure, or can be output as various combinations. When input files (for input samples) are available, ratio-over-input are displayed as well. Statistical comparisons between samples or between features can be plotted as boxplots or barplots of means 0b1 S.E.

centerfiles <- system.file("extdata", "test_chip_peak_chr19.narrowPeak", package="GenomicPlot")
 names(centerfiles) <- c("NarrowPeak")
 queryfiles <- c(system.file("extdata", "treat_chr19.bam", package="GenomicPlot"),
                 system.file("extdata", "chip_treat_chr19.bam", package="GenomicPlot"))
 names(queryfiles) <- c("clip_bam", "chip_bam")
 inputfiles <- c(system.file("extdata", "input_chr19.bam", package="GenomicPlot"),
                 system.file("extdata", "chip_input_chr19.bam", package="GenomicPlot"))
 names(inputfiles) <- c("clip_input", "chip_input")

 importParams <- list(offset=0, fix_width=150, fix_point="start", norm=TRUE, 
                           useScore=FALSE, outRle=TRUE, useSizeFactor=FALSE, genome="hg19")

 plot_region(queryFiles=queryfiles, 
             centerFiles=centerfiles, 
             inputFiles=inputfiles, 
             nbins=100, 
             heatmap=TRUE, 
             scale=FALSE,  
             regionName="narrowPeak", 
             importParams=importParams, 
             verbose=FALSE, 
             fiveP=-500, 
             threeP=500, 
             smooth=TRUE, 
             transform=NA, 
             stranded=TRUE, 
             outPrefix=NULL, 
             rmOutlier=0, 
             nc=5)
Individual sample profile

Individual sample profile

Individual sample coverage stats in narrowPeak

Individual sample coverage stats in narrowPeak

Individual sample coverage profiles and heatmaps in narrowPeak

Individual sample coverage profiles and heatmaps in narrowPeak

Ratio-over-input profile

Ratio-over-input profile

Ratio-over-input stats

Ratio-over-input stats

Ratio-over-input profiles and heatmaps

Ratio-over-input profiles and heatmaps

Program names and arguments

Program names and arguments

Plot start, end and center of a genomic feature

When the intron splicing sites are focus of studies, we want to inspect signals at both 5’ splicing sites and 3’ splicing sites, perhaps want to contrast with the center of introns as well, then displaying all 3 pieces of information in the same panel would be desirable.

txdb <- AnnotationDbi::loadDb(system.file("extdata", "txdb_chr19.sql", package="GenomicPlot"))
queryfiles <- system.file("extdata", "treat_chr19.bam", package="GenomicPlot")
names(queryfiles) <- "clip_bam"
inputfiles <- system.file("extdata", "input_chr19.bam", package="GenomicPlot")
names(inputfiles) <- "clip_input"
ext <- c(-500, 200, -200, 500)
hl <- c(-50, 50, -50, 50)

importParams <- list(offset=-1, fix_width=0, fix_point="start", norm=TRUE, 
                          useScore=FALSE, outRle=TRUE, useSizeFactor=FALSE, genome="hg19")
plot_start_end(queryFiles=queryfiles, 
               inputFiles=inputfiles, 
               txdb=txdb, 
               centerFiles="intron", 
               binSize=10,
               importParams=importParams, 
               ext=ext, 
               hl=hl, 
               insert=100, 
               stranded=TRUE, 
               scale=FALSE, 
               smooth=TRUE, 
               outPrefix=NULL, 
               nc=5)
Query and input sample profiles in start, center and end of intron

Query and input sample profiles in start, center and end of intron

Ratio-over profile in start, center and end of intron

Ratio-over profile in start, center and end of intron

Plot genomic loci (start, end or center of a feature)

Difference in signal intensity within specific regions around the reference loci can be tested, and the test statistics can be plotted as boxplot and barplot of mean +/- SE. The test can be done among loci or among samples.

 centerfiles <- c(system.file("extdata", "test_clip_peak_chr19.bed", package="GenomicPlot"),
                  system.file("extdata", "test_chip_peak_chr19.bed", package="GenomicPlot"))
 names(centerfiles) <- c("iCLIPPeak", "SummitPeak")
 queryfiles <- c(system.file("extdata", "treat_chr19.bam", package="GenomicPlot"),
                 system.file("extdata", "chip_treat_chr19.bam", package="GenomicPlot"))
 names(queryfiles) <- c("clip_bam", "chip_bam")
 inputfiles <- c(system.file("extdata", "input_chr19.bam", package="GenomicPlot"),
                 system.file("extdata", "chip_input_chr19.bam", package="GenomicPlot"))
 names(inputfiles) <- c("clip_input", "chip_input")

 importParams <- list(offset=0, fix_width=150, fix_point="start", norm=TRUE, 
                           useScore=FALSE, outRle=TRUE, useSizeFactor=TRUE, genome="hg19")

 plot_locus(queryFiles=queryfiles, 
            centerFiles=centerfiles, 
            ext=c(-500,500), 
            hl=c(-100,100), 
            shade=TRUE, 
            smooth=TRUE, 
            importParams=importParams, 
            binSize=10, 
            refPoint="center", 
            Xlab="Center", 
            inputFiles=inputfiles, 
            stranded=TRUE, 
            scale=FALSE, 
            outPrefix=NULL, 
            verbose=FALSE, 
            transform=NA, 
            rmOutlier=0, 
            statsMethod="wilcox.test", 
            heatmap=TRUE, 
            nc=5)
Ratio-over-input for clip signal around clip and chip peaks

Ratio-over-input for clip signal around clip and chip peaks

Ratio-over-input for clip signal around clip and chip peaks

Ratio-over-input for clip signal around clip and chip peaks

Ratio-over-input for chip signal around clip and chip peaks

Ratio-over-input for chip signal around clip and chip peaks

Ratio-over-input for chip signal around clip and chip peaks

Ratio-over-input for chip signal around clip and chip peaks

Ratio-over-input for chip and clip signal around clip peaks

Ratio-over-input for chip and clip signal around clip peaks

Ratio-over-input for chip and clip signal around clip peaks

Ratio-over-input for chip and clip signal around clip peaks

Ratio-over-input for chip and clip signal around chip peaks

Ratio-over-input for chip and clip signal around chip peaks

Ratio-over-input for chip and clip signal around chip peaks

Ratio-over-input for chip and clip signal around chip peaks

Ratio-over-input profiles for chip and clip signal around clip and chip peaks

Ratio-over-input profiles for chip and clip signal around clip and chip peaks

Ratio-over-input profiles and heatmap for chip and clip signal

Ratio-over-input profiles and heatmap for chip and clip signal

Plot genomic loci with random sites as contrast

Random sites that deviate from the reference loci within a specified maximum distance can be treated as a control, and the statistical tests will be performed between bona fide and the random sites. Here the reference sites located in different genomic features (5’UTR, CDS, 3’UTR) are tested separately. To avoid sampling bias, increase “n_random”.

txdb <- AnnotationDbi::loadDb(system.file("extdata", "txdb_chr19.sql", package="GenomicPlot"))
 centerfiles <- c(system.file("extdata", "test_clip_peak_chr19.bed", package="GenomicPlot"))
 names(centerfiles) <- c("iCLIPPeak")
 queryfiles <- c(system.file("extdata", "treat_chr19.bam", package="GenomicPlot"))
 names(queryfiles) <- c("clip_bam")
 inputfiles <- c(system.file("extdata", "input_chr19.bam", package="GenomicPlot"))
 names(inputfiles) <- c("clip_input")

importParams <- list(offset=-1, fix_width=150, fix_point="start", norm=TRUE, 
                          useScore=FALSE, outRle=TRUE, useSizeFactor=TRUE, genome="hg19")

plot_locus_with_random(queryFiles=queryfiles, 
                       centerFiles=centerfiles, 
                       txdb, 
                       ext=c(-500,500), 
                       hl=c(-100,100), 
                       shade=TRUE, 
                       importParams=importParams, 
                       binSize=10, 
                       refPoint="center", 
                       Xlab="Center", 
                       smooth=TRUE,
                       inputFiles=inputfiles, 
                       stranded=TRUE, 
                       scale=FALSE, 
                       outPrefix=NULL, 
                       verbose=FALSE, 
                       transform=NA, 
                       rmOutlier=0, 
                       n_random=1, 
                       statsMethod="wilcox.test", 
                       nc=5)
Ratio-over-input for clip signal around clip peaks in 5'UTR

Ratio-over-input for clip signal around clip peaks in 5’UTR

Ratio-over-input for clip signal around clip peaks in 5'UTR

Ratio-over-input for clip signal around clip peaks in 5’UTR

Ratio-over-input for clip signal around clip peaks

Ratio-over-input for clip signal around clip peaks

Ratio-over-input for clip signal around clip peaks

Ratio-over-input for clip signal around clip peaks

Plot peak annotation statistics

Aside from reads coverage profiles, distribution of binding peaks in different gene types and genomic features is also important. Peak annotation statistics are plotted as bar chart for distribution in gene types, and as pie charts for distribution in genomic features. The pie charts are plotted in two different ways: either as percentage of absolute counts or as percentage of feature length-normalized counts in each features. For DNA binding samples, the features, in order of precedence, include “Promoter”, “TTS”, “5’UTR”, “CDS”, “3’UTR” and “Intron”; for RNA binding samples, “Promoter” and “TTS” are excluded. “Promoter” is defined as regions 2000 bp upstream of transcription start site (TSS) and 300 bp downstream TSS, “TTS” is defined as the region 1000 bp downstream cleavage site or the length between cleavage site and the start of the next gene, whichever is shorter, but these lengths can be adjusted. To save annotation results (both peak-oriented and gene-oriented), set “verbose”=TRUE.


gtffile <- system.file("extdata", "gencode.v19.annotation_chr19.gtf", package="GenomicPlot")

centerfile <- system.file("extdata", "test_chip_peak_chr19.bed", package="GenomicPlot")
names(centerfile) <- c("SummitPeak")

handleBedparams <- list(fix_width=0, fix_point="center", useScore=FALSE, outRle=FALSE, 
                        offset=0, norm=FALSE, useSizeFactor=FALSE, genome="hg19")

pa <- plot_peak_annotation(peakFile=centerfile, 
                           gtfFile=gtffile, 
                           importParams=handleBedparams, 
                           fiveP=-2000, 
                           dsTSS=300, 
                           threeP=1000, 
                           simple=FALSE, 
                           verbose=TRUE, 
                           outPrefix=NULL)
Distribution of chip peak in various types of gene

Distribution of chip peak in various types of gene

Distribution of chip peak in various parts of gene

Distribution of chip peak in various parts of gene

Density of chip peak in various parts of gene

Density of chip peak in various parts of gene